package entity

import (
	"strconv"
	"time"

	"shqsoft.cn/pasnj/base"
	"shqsoft.cn/pasnj/bi/cube"
)

//  INDI_LOAN 对私_个人贷款明细
type INDI_LOAN struct {
	ID      int       `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	Idno    string    `gorm:"column:IDNO"` //身份证号
	Jjh     string    `gorm:"column:借据号"`
	Htbh    string    `gorm:"column:合同编号"`
	Zhangh  string    `gorm:"column:帐号"`
	Khwd    string    `gorm:"column:开户网点"`
	Bizhong string    `gorm:"column:币种"`
	Khmc    string    `gorm:"column:客户名称"`
	Dkzl    string    `gorm:"column:贷款种类"`
	Dkmc    string    `gorm:"column:贷款名称"`
	Dklx    string    `gorm:"column:贷款类型"`
	Sfkfdk  string    `gorm:"column:是否开发贷款"`
	Ddb     string    `gorm:"column:短贷宝"`
	Jydw    string    `gorm:"column:经营单位"`
	Kemu    int       `gorm:"column:科目"`
	Jgid    int       `gorm:"column:机构ID"`
	Dqs     int       `gorm:"column:当期数"`
	Zhzt    int       `gorm:"column:帐户状态"`
	Zqs     int       `gorm:"column:总期数"`
	Zhid    int       `gorm:"column:帐户ID"`
	Fdll    int       `gorm:"column:浮动利率"`
	Ffje    float64   `gorm:"column:发放金额"`
	Lilu    float64   `gorm:"column:利率"`
	Dkbbl   float64   `gorm:"column:贷款拔备率"`
	Jzll    float64   `gorm:"column:基准利率"`
	Srye    float64   `gorm:"column:上日余额"`
	Dqye    float64   `gorm:"column:当前余额"`
	Khrj    float64   `gorm:"column:开户日均"`
	Jrj     float64   `gorm:"column:季日均"`
	Nrj     float64   `gorm:"column:年日均"`
	Qxr     time.Time `gorm:"column:起息日";type:date;`
	Dqr     time.Time `gorm:"column:到期日";type:date;`
	Xhr     time.Time `gorm:"column:销户日";type:date;`
	YG1     string    `gorm:"-"`
	ZB1     *float64  `gorm:"-"`
	YG2     string    `gorm:"-"`
	ZB2     *float64  `gorm:"-"`
	YG3     string    `gorm:"-"`
	ZB3     *float64  `gorm:"-"`
	YG4     string    `gorm:"-"`
	ZB4     *float64  `gorm:"-"`
	YG5     string    `gorm:"-"`
	ZB5     *float64  `gorm:"-"`
}

//TableName User用户表名
func (INDI_LOAN) TableName() string {
	return "V_对私_个人贷款明细"

}

// AfterFind 选择男女
func (c *INDI_LOAN) AfterFind() (err error) {
	var share *cube.Share
	share, err = cube.GetShare("indi_loan_divi")
	if err != nil {
		return
	}
	var diviMap map[string]float64
	diviMap, err = share.GetDivision(strconv.Itoa(c.ID))
	if err != nil {
		return
	}
	i := 0
	for k, v := range diviMap {
		val := v
		i++
		switch i {
		case 1:
			c.YG1 = k
			c.ZB1 = &val
		case 2:
			c.YG2 = k
			c.ZB2 = &val
		case 3:
			c.YG3 = k
			c.ZB3 = &val
		case 4:
			c.YG4 = k
			c.ZB4 = &val
		case 5:
			c.YG5 = k
			c.ZB5 = &val
		default:
			break
		}
	}
	return
}

//V_Divi_CxEF 对私_个人贷款明细
func INDI_LOANEF() base.EntityFunc {
	return func() interface{} {
		entity := INDI_LOAN{}
		return &entity
	}
}

//ZTXMCMXESF 对私_个人贷款明细
func INDI_LOANESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []INDI_LOAN
		return &entities
	}
}
func init() {
	dao := base.NewDefaultDao(INDI_LOANEF(), INDI_LOANESF(), nil)
	filter := base.DefaultFilter{
		FilterColName: "ID",
		TableName:     "T_INDI_LOAN_DIVI",
		EmidColName:   "EMID",
		AcidColName:   "ACID",
		WhereCause:    "ISWO=0 AND WODT IS NULL",
	}
	dao.Fileter = &filter
	base.DaoPoolObj.Put("INDI_LOAN", dao)
}
